package org.zpmis.api.http;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.zpmis.api.business.StatisticsWebService;
import org.zpmis.common.base.BaseController;
import org.zpmis.common.exception.BusinessException;
import org.zpmis.common.result.PlatformResult;
import org.zpmis.domain.order.qo.StatisticsQo;

import javax.annotation.Resource;

/**
* created with CodeGenerator
* description: 统计操作接口
* @author  Yang
* date: 2021-6-2
* time: 14:53:29
*/
@RestController
@RequestMapping("/statistics")
@Slf4j
public class StatisticsController extends BaseController{

    @Resource
    private StatisticsWebService statisticsWebService;


    /**
     * 订单回款统计柱状图
     * @param statisticsQo
     * @return
     */
    @PostMapping("/orderHistogramStatistics")
    public PlatformResult orderHistogramStatistics(@Validated @RequestBody StatisticsQo statisticsQo){
        try {
            return PlatformResult.success(statisticsWebService.orderHistogramStatistics(statisticsQo));
        } catch (BusinessException e) {
            log.error("[StatisticsController]---orderHistogramStatistics--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[StatisticsController]---orderHistogramStatistics--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 订单数量统计图
     * @param statisticsQo
     * @return
     */
    @PostMapping("/orderCountStatistics")
    public PlatformResult orderCountStatistics(@Validated @RequestBody StatisticsQo statisticsQo){
        try {
            return PlatformResult.success(statisticsWebService.orderCountStatistics(statisticsQo));
        } catch (BusinessException e) {
            log.error("[StatisticsController]---orderCountStatistics--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[StatisticsController]---orderCountStatistics--->Exception:",e);
            return PlatformResult.failure();
        }
    }
    /**
     * 账单回款统计柱状图
     * @param statisticsQo
     * @return
     */
    @PostMapping("/contractHistogramStatistics")
    public PlatformResult contractHistogramStatistics(@Validated @RequestBody StatisticsQo statisticsQo){
        try {
            return PlatformResult.success(statisticsWebService.contractHistogramStatistics(statisticsQo));
        } catch (BusinessException e) {
            log.error("[StatisticsController]---contractHistogramStatistics--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[StatisticsController]---contractHistogramStatistics--->Exception:",e);
            return PlatformResult.failure();
        }
    }

    /**
     * 合同数量统计状图
     * @param statisticsQo
     * @return
     */
    @PostMapping("/contractCountStatistics")
    public PlatformResult contractCountStatistics(@Validated @RequestBody StatisticsQo statisticsQo){
        try {
            return PlatformResult.success(statisticsWebService.contractCountStatistics(statisticsQo));
        } catch (BusinessException e) {
            log.error("[StatisticsController]---contractCountStatistics--->BusinessException:",e);
            return PlatformResult.failure(e.getResultCode());
        } catch (Exception e) {
            log.error("[StatisticsController]---contractCountStatistics--->Exception:",e);
            return PlatformResult.failure();
        }
    }
}
